Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(insights): Make HogQL queries limit_context-aware #21022

Merged
merged 6 commits into from
Mar 21, 2024

Conversation

Twixes
Copy link
Member

@Twixes Twixes commented Mar 19, 2024

Problem

I found that enabling async queries did not extend the max execution time for most insight types. In fact, it only did so for SQL insights. This meant we weren't able to realize the benefits of background execution for insights.

Changes

Added limit_context to the relevant execute_hogql_query() calls. This makes async queries much more powerful an escape hatch.

How did you test this code?

Added a few query tests, though this is cumbersome – see the thread for more.

@Twixes Twixes requested review from webjunkie and Gilbert09 March 19, 2024 22:20
Comment on lines +201 to +206
@patch("posthog.hogql.query.sync_execute", wraps=sync_execute)
def test_limit_is_context_aware(self, mock_sync_execute: MagicMock):
self._run_web_overview_query("2023-12-01", "2023-12-03", limit_context=LimitContext.QUERY_ASYNC)

mock_sync_execute.assert_called_once()
self.assertIn(f" max_execution_time={INCREASED_MAX_EXECUTION_TIME},", mock_sync_execute.call_args[0][0])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's really tedious and brittle that we don't have a way to add a test for common mechanics to ALL query runner suites. limit_context-awareness is one thing that needs to be guaranteed for each implementation, as they implement their own calculate()s.

It looks like we could use a QueryRunnerTest base class that would inherit from ClickhouseTestMixin and have run_query() and run_actors_query(). Was there a reason for not doing that? @Gilbert09 @webjunkie

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it was because of the conversion of tests basically is copying one by one the legacy tests and nobody worried about combining code or functionality yet 🙈

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Cool, makes sense. I don't have the time to do this right now, but useful to do in some nearish future

Copy link
Contributor

@webjunkie webjunkie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow, thank you for noticing this!

Comment on lines +201 to +206
@patch("posthog.hogql.query.sync_execute", wraps=sync_execute)
def test_limit_is_context_aware(self, mock_sync_execute: MagicMock):
self._run_web_overview_query("2023-12-01", "2023-12-03", limit_context=LimitContext.QUERY_ASYNC)

mock_sync_execute.assert_called_once()
self.assertIn(f" max_execution_time={INCREASED_MAX_EXECUTION_TIME},", mock_sync_execute.call_args[0][0])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it was because of the conversion of tests basically is copying one by one the legacy tests and nobody worried about combining code or functionality yet 🙈

@Twixes Twixes enabled auto-merge (squash) March 21, 2024 17:44
@Twixes Twixes merged commit f5e4b17 into master Mar 21, 2024
125 of 127 checks passed
@Twixes Twixes deleted the limit-context-aware-queries branch March 21, 2024 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants